<?php

class FeedsController extends AppController
{
    var $name = 'Feeds';
    var $scaffold;
    var $helpers = array('Javascript', 'Ajax');
	var $components = array('Acl');

    function index($id ='1')
    {

    	// TODO: new method needed....
    	if ( $this->Session->Check('User') ){
    		$uinfo = $this->Session->read('User');
    	} else {
    		$uinfo['id'] = 0;
    		$uinfo['username'] = 'Guest';
    	}
    	$this->set('user', $uinfo['username']);

		$tofilter = $this->Feed->findAll();
    	$buf=Array();
    	foreach($tofilter as $feed){
    			if ( $this->Acl->check($uinfo['username'], $feed['Feed']['name'], $action = "read") ){
    				$buf[] = $feed;
    			}
    	}
    	$this->set('feeds', $buf);
    }

    function slideshow($id = '1')
    {
        $this->Feed->id = $id;
        $data = $this->Feed->read();
        if (!isset($data)) die('No results');   // TODO do this the clean way


        $this->set('feed', $data);
        $this->pageTitle=$data['Feed']['name']; // the Title of the page

    }

   function css($id=NULL)
   {
   		if ( !$id ) exit;		//no id, no css
   		$this->Feed->id= $id;
   		$data = $this->Feed->read('stylesheet'); // only read the stylesheet field
   		if (!isset($data)) die('No results');   // TODO do this the clean way

        $this->set('css', $data['Feed']['stylesheet']);
   }

   function edit($id=NULL)
   {
   		if ( $this->Session->Check('User') ){
    		$uinfo = $this->Session->read('User');
    	} else {
    		$uinfo['id'] = 0;
    		$uinfo['username'] = 'Guest';
    	}
   		if ( !$this->Acl->check($uinfo['username'], 'feeds', $action = "update") ){
			die('No update access on Feeds.');
		}
   		$this->Feed->id = $id;
        $data = $this->Feed->read();
        if (!isset($data)) die('No results');   // TODO do this the clean way
		if ( ! $this->Acl->check($uinfo['username'], $data['Feed']['name'], $action = "update") )
		{
    		die('Could not edit that feeds');
		}
   }

}

?>